﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace We.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UploadController : ControllerBase
    {
         public UploadController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }

        [HttpPost]
        public IActionResult Up(IFormFile file)
        {

            var neww = Guid.NewGuid().ToString();
             var path=Web.WebRootPath +@"\pic\"+ neww+file.FileName;
            using (FileStream fs = System.IO.File.Create(path))
            {
                 file.CopyTo(fs);
                 fs.Close();
            }

            return Ok(@"/pic/" + neww+ file.FileName);

        }
    }
}
